package com.example.client.netty;

import com.example.node.Client;
import com.example.node.Node;
import com.example.factory.DefaultClientFactory;
import com.example.transport.message.Request;
import com.example.transport.message.Response;

public class DefaultNettyClientFactory extends DefaultClientFactory {
    private Client client;
    private String ip;
    private int port;

    @Override
    public Node getNode() {
        if (this.client == null) {
            this.client = new DefaultNettyClient(ip, port);
        }
        return this.client;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public void asyncSend(Request request) throws Exception {
        ((DefaultNettyClient) getNode()).asyncSend(request);
    }

    @Override
    public Response syncSend(Request request) throws Exception {
        return ((DefaultNettyClient) getNode()).syncSend(request);
    }
}
